package com.cros.pruebas;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.PriorityQueue;
import java.util.Set;
import java.util.TreeSet;

public class PriorityQueuesExampels {
	
	static class PQsort implements Comparator<Integer> { // inverse sort
		public int compare(Integer one, Integer two) {
			return two - one; // unboxing
		}
	}
	
static class Perro implements Comparable<Perro>{
	private String name;
	public Perro(String name){
		this.name=name;
	}
	public int compareTo(Perro p){
		return this.name.compareTo(p.name);
	}
	public String toString(){
		return this.name;
	}
}

static class PerroComparator implements Comparator<Perro>{

	@Override
	public int compare(Perro arg0, Perro arg1) {
		return arg1.name.compareTo(arg0.name);
	}
	
}


static class Personal implements Comparable<Personal>{
	private String name;
	public Personal(String name){
		this.name=name;
	}
	public int compareTo(Personal p){
		return this.name.compareTo(p.name);
	}
	
	public boolean equals(Object o){
		Personal p = (Personal)o;
		return this.name.equals(p.name);
		
	}
	public String toString(){
		return this.name;
	}
	
}


static class PersonalComparator implements Comparator<Personal>{
	public int compare(Personal p,Personal s){
		return s.name.compareTo(p.name);
	}
	
	
}
	
	
public static void main(String argv[]){
	PersonalComparator pc = new PersonalComparator();
	TreeSet<Personal> s = new TreeSet<Personal>();
	s.add(new Personal("sebatian"));	
	s.add(new Personal("and"));
	s.add(new Personal("becerro"));	
	s.add(new Personal("rodo"));
	s.add(new Personal("fea"));	
	s.add(new Personal("elias"));	
	s.add(new Personal("eto"));
	s.add(new Personal("fa"));
	s.add(new Personal("mama"));	
	s.add(new Personal("zebatian"));
	TreeSet sub = (TreeSet)s.subSet(new Personal("elias"),false,new Personal("mama"),false);
	System.out.println(s);
	System.out.println(sub);
}


public void temporalTres(){
	HashMap map = new HashMap();
	map.put("cuatro","cuantro value");
	map.put("uno","uno value");
	map.put("tres","tres value");
	map.put("dos","dos value");
	Set s = map.keySet();
	System.out.println(map);
	s = new TreeSet(s);
	System.out.println(s);
	s.add("f");
	s.add("a");
	s.add("a");
	System.out.println(s);
}
public void temporal2(){
	PerroComparator pc = new PerroComparator();
	PriorityQueue<Perro> perrosqu = new PriorityQueue<Perro>(10,pc);
	perrosqu.add(new Perro("rodo"));
	perrosqu.add(new Perro("aldo"));
	perrosqu.add(new Perro("aldo"));
	perrosqu.add(new Perro("diego"));
	for(int i=0;i<5;i++){
		System.out.println(perrosqu.poll());
	}
}
public void temporal(){
	int[] ia = {1,5,3,7,6,9,8}; // unordered data
	PriorityQueue<Integer> pq1 = new PriorityQueue<Integer>(); // use natural order
	for(int x : ia)
		pq1.offer(x);
	System.out.println("l-"+pq1.size());
	
	
	for(int x : ia) // review queue
		System.out.print(pq1.poll() + " ");
	
	System.out.println("");
		
	System.out.println("2-"+pq1.size());
		
		PQsort pqs = new PQsort(); // get a Comparator
		PriorityQueue<Integer> pq2 =
		new PriorityQueue<Integer>(10,pqs); // use Comparator
		for(int x : ia) // load queue
		pq2.offer(x);
		
		System.out.println("size " + pq2.size());
		System.out.println("peek " + pq2.peek());
		System.out.println("size " + pq2.size());
		System.out.println("poll " + pq2.poll());
		System.out.println("size " + pq2.size());
		
		for(int x : ia) // review queue
		System.out.print(pq2.poll() + " ");
}

}
